<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar @click-left="show = !show" :fixed="false" :back="!show" color="#fff" title="档案管理"></uni-navbar></view>

		<view class="search-view"><u-search class="search-input" shape="square" :show-filter="true" @change="search" @search="search" @custom="show = !show"></u-search></view>

		<scroll-view scroll-y="true" class="filter-box" v-if="show" @touchmove.stop>
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="性别">
						<u-input v-model="sex" type="select" :select-open="sexShow" placeholder="请选择性别" @click="sexShow = true" />
						<u-select :list="sexList" v-model="sexShow" @confirm="sexConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="民族">
						<u-input v-model="nation" type="select" :select-open="nationShow" placeholder="请选择民族" @click="nationShow = true" />
						<u-select :list="nationList" v-model="nationShow" @confirm="nationConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="年龄">
						<u-input v-model="birthday" type="select" :select-open="birthdayShow" placeholder="请选择年龄" @click="birthdayShow = true" />
						<u-select :list="birthdayList" v-model="birthdayShow" @confirm="birthdayConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="学历">
						<u-input v-model="xueli" type="select" :select-open="xueliShow" placeholder="请选择学历" @click="xueliShow = true" />
						<u-select :list="xueliList" v-model="xueliShow" @confirm="xueliConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="党派">
						<u-input v-model="dangpai" type="select" :select-open="dangpaiShow" placeholder="请选择党派" @click="dangpaiShow = true" />
						<u-select :list="dangpaiList" v-model="dangpaiShow" @confirm="dangpaiConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="代表团">
						<u-input v-model="wyhdz" type="select" :select-open="wyhdzShow" placeholder="请选择代表团" @click="wyhdzShow = true" />
						<u-select :list="wyhdzList" v-model="wyhdzShow" @confirm="wyhdzConfirm"></u-select>
					</u-form-item>
					<!-- <u-form-item class="form-item" label="代表活动组">
						<u-input v-model="xsqhdz" type="select" :select-open="xsqhdzShow" placeholder="请选择代表活动组" @click="xsqhdzShow = true" />
						<u-select :list="xsqhdzList" v-model="xsqhdzShow" @confirm="xsqhdzConfirm"></u-select>
					</u-form-item> -->
					<!-- <u-form-item class="form-item" label="专委会">
						<u-input v-model="dept" type="select" :select-open="deptShow" placeholder="请选择专委会" @click="deptShow = true" />
						<u-select :list="deptList" v-model="deptShow" @confirm="deptConfirm"></u-select>
					</u-form-item> -->
					<!-- <u-form-item class="form-item" label="界别">
						<u-input v-model="jiebie" type="select" :select-open="jiebieShow" placeholder="请选择界别" @click="jiebieShow = true" />
						<u-select :list="jiebieList" v-model="jiebieShow" @confirm="jiebieConfirm"></u-select>
					</u-form-item> -->
					<!-- <u-form-item class="form-item" label="角色">
						<u-input v-model="role" type="select" :select-open="roleShow" placeholder="请选择角色" @click="roleShow = true" />
						<u-select :list="roleList" v-model="roleShow" @confirm="roleConfirm"></u-select>
					</u-form-item> -->
					<u-form-item class="form-item" label="届次">
						<u-input v-model="jieci" type="select" :select-open="jcShow" placeholder="请选择届次" @click="jcShow = true" />
						<u-select v-model="jcShow" mode="mutil-column-auto" :list="jcList" @confirm="jcConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="连任界数">
						<u-input v-model="lianren" type="select" :select-open="lianrenShow" placeholder="请选择连任界数" @click="lianrenShow = true" />
						<u-select :list="lianrenList" v-model="lianrenShow" @confirm="lianrenConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="历任界数">
						<u-input v-model="liren" type="select" :select-open="lirenShow" placeholder="请选择历任界数" @click="lirenShow = true" />
						<u-select :list="lirenList" v-model="lirenShow" @confirm="lirenConfirm"></u-select>
					</u-form-item>
				</u-form>
			</view>
			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" @click="filter">确定</u-button>
				</view>
			</view>
		</scroll-view>

		<!-- <view class="filter-box" v-if="show" @touchmove.stop="">
		</view> -->

		<view class="united-box">
			<view class="united-ttl">
				<image class="image" src="/static/img/icon04.png" mode="widthFix"></image>
				<view class="dept" @click="deptsShow = true">
					<!-- <view class="dept"> -->
					{{ depts }}
					<u-icon class="right-icon" :class="{ reverse: deptsShow }" name="arrow-down-fill" size="26" color="#c0c4cc"></u-icon>
				</view>
				<view class="ttl-btn" @click="navTo('/pagesB/united/statistics')">统计分析</view>
				<!-- <u-select :list="deptList" v-model="deptsShow" @confirm="deptsConfirm"></u-select> -->
				<select-tree ref="deptsTree" :show="deptsShow" :range="deptsList" :selected="deptsStr" :numShow="true" :multiple="false" :selectParent="true" @confirm="treeConfirm($event, 'depts')" @cancel="treeCancel($event, 'depts')"></select-tree>
			</view>

			<view class="list-box">
				<view class="list-info_02" v-for="item in infoList" :key="item.id" @click="navTo('/pagesB/united/detail?id=' + item.id)">
					<view class="left">
						<view class="info-title">{{ item.name }}</view>
						<view class="info-btm">{{ item.wyhdz || '' }}</view>
					</view>
					<view class="right" @click.stop="call(item.phoneNumber)">{{ item.phoneNumber || '' }}</view>
				</view>
			</view>

			<u-loadmore :status="loading"></u-loadmore>
		</view>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>
	</view>
</template>

<script>
import selectTree from '@/components/uni-select-tree.vue';
import { mapState } from 'vuex';
export default {
	components: {
		selectTree
	},
	data() {
		return {
			show: false,
			scrollTop: 0,
			colorMap: {
				0: '#0099ff',
				1: '#ff9900',
				2: '#19be6b'
			},
			title: '',

			front_political: '',
			front_education: '',
			front_orange: '',
			kind: '',

			ids: [],

			sex: '',
			sexShow: false,
			sexList: [
				{
					value: '男',
					label: '男'
				},
				{
					value: '女',
					label: '女'
				}
			],

			nation: '',
			nationShow: false,
			nationList: [],

			birthday: '',
			birthdayShow: false,
			birthdayList: [],

			xueli: '',
			xueliShow: false,
			xueliList: [],

			dangpai: '',
			dangpaiShow: false,
			dangpaiList: [],

			wyhdz: '',
			wyhdzShow: false,
			wyhdzList: [],

			xsqhdz: '',
			xsqhdzShow: false,
			xsqhdzList: [],

			jiebie: '',
			jiebieShow: false,
			jiebieList: [],

			deptsId: [],
			depts: '人大代表',
			deptsStr: '',
			deptsShow: false,
			deptsList: [],

			dept: '',
			deptShow: false,
			deptList: [],

			role: '',
			roleCode: 'changwei,weiyuan',
			roleShow: false,
			roleList: [],

			jieci: '',
			jcShow: false,
			jcList: [],

			liren: '',
			lirenShow: false,
			lirenList: [],

			lianren: '',
			lianrenShow: false,
			lianrenList: [],

			typeList: [],

			navIndex: 0,
			infoList: [],

			jieId: '',
			ciId: '',
			info: {
				clientCode: '',
				zxjiguan: '',
				keshi: '',
				status: '1,2',
				sex: '',
				nation: '',
				birthday: '',
				xueli: '',
				dangpai: '',
				wyhdz: '',
				remark4: '',
				jiebie: '',
				liren: '',
				deptId: '',
				name: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadData();
		// this.loadDict('sex', 'sexList');
		this.loadDict('nation', 'nationList');
		this.loadDict('nianling', 'birthdayList');
		this.loadDict('xueli', 'xueliList');
		this.loadDict('dangpai', 'dangpaiList');
		this.loadDict('wyhdz', 'wyhdzList');
		this.loadDict('xsqhdz', 'xsqhdzList');
		this.loadDict('jiebie', 'jiebieList');
		this.loadDict('lianren', 'lirenList');
		this.loadDict('lianren', 'lianrenList');
		this.loadDept();
		this.loadDepts();
		this.loadRoles();
		this.jieciData();
	},
	onPullDownRefresh() {
		if (!this.show) this.loadData('refresh');
	},
	onReachBottom() {
		if (!this.show && this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.info.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.jieId = this.userInfo.jieCi.pid;
				this.ciId = this.userInfo.jieCi.id;

				this.pageNum = 1;
				this.pageSize = 15;
			} else {
				this.$logout();
			}
		},
		loadDict(type, list) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				this[list] = [];
				res.data.forEach((item) => {
					this[list].push({
						value: item.dictValue,
						label: item.dictName
					});
				});
			});
		},
		loadRoles() {
			this.$request('/system/sys-role/roles', {
				clientCode: this.clientCode,
				currentUserId: this.userId
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				this.roleList = [];
				res.data.forEach((item) => {
					this.roleList.push({
						id: item.id,
						value: item.roleCode,
						label: item.roleName
					});
				});
			});
		},
		loadDept() {
			this.$request('/system/sys-dept/depts', {
				clientCode: this.clientCode,
				weishi: 1
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				this.deptList = [];
				res.data.forEach((item) => {
					this.deptList.push({
						value: item.id,
						label: item.deptName
					});
				});
			});
		},
		loadDepts() {
			this.$request('/system/user-info/jgksTree', {
				jieId: this.jieId,
				ciId: this.ciId,
				clientCode: this.clientCode
			}).then((res) => {
				if (!res.data) {
					return false;
				}
				this.deptsList = res.data;
			});
		},
		jieciData() {
			let data = {
				clientCode: this.clientCode,
				jieCi: {
					pid: ''
				}
			};
			this.$request('/jie-ci/list', data).then((res) => {
				this.jcList = [];
				let jieArr = [];
				let ciArr = [];
				res.data.forEach((item) => {
					data.jieCi.pid = item.id;
					this.$request('/jie-ci/list', data).then((res) => {
						ciArr = [];
						res.data.forEach((key) => {
							ciArr.push({
								value: key.id,
								label: key.name
							});
						});
						this.jcList.push({
							value: item.id,
							label: item.name,
							children: ciArr
						});
					});
				});
			});
		},
		loadData(type = 'add') {
			if (type == 'add' && this.loading == 'loading') {
				return false;
			}
			if (type == 'add' && this.loading == 'nomore') {
				return false;
			}

			this.loading = 'loading';
			if (type != 'add') {
				this.pageNum = 1;
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				jieId: this.jieId,
				ciId: this.ciId,
				userId: this.userId,
				roleCode: 'changwei,weiyuan',
				status: '1,2',
				// isAsc: '1',
				// orderColumn: 'orderNum',
				userInfo: this.info
			};

			this.$request('/system/user-info/list', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.infoList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.infoList = this.infoList.concat(res.data.records);
				this.loaded = true;
				if (this.infoList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		treeConfirm(e, type) {
			console.log(e);
			if (!e || e.length == 0) {
				this[type + 'Show'] = false;
				this[type + 'Name'] = '';
				this[type + 'Ids'] = [];
				return false;
			}

			this.depts = e[0].name;
			this.info.wy = '';
			this.info.wyhdz = '';

			if (!!e[0].key) {
				switch (e[0].key) {
					case 'wyhdz':
						this.info.wyhdz = e[0].id;
						break;
					case 'wy':
						this.info.wy = '';
						break;
					default:
						break;
				}
			}

			this[type + 'Ids'] = [e[0].id];
			this[type + 'Name'] = e[0].name;
			this[type + 'Show'] = false;

			this.loadData('refresh');
		},
		treeCancel(e, type) {
			this[type + 'Show'] = false;
		},
		sexConfirm(e) {
			this.sex = e[0].label;
			this.info.sex = e[0].value;
		},
		nationConfirm(e) {
			this.nation = e[0].label;
			this.info.nation = e[0].value;
		},
		birthdayConfirm(e) {
			this.birthday = e[0].label;
			this.info.birthday = e[0].value;
		},
		xueliConfirm(e) {
			this.xueli = e[0].label;
			this.info.xueli = e[0].value;
		},
		dangpaiConfirm(e) {
			this.dangpai = e[0].label;
			this.info.dangpai = e[0].value;
		},
		wyhdzConfirm(e) {
			this.wyhdz = e[0].label;
			this.info.wyhdz = e[0].value;
		},
		xsqhdzConfirm(e) {
			this.xsqhdz = e[0].label;
			this.info.remark4 = e[0].value;
		},
		jiebieConfirm(e) {
			this.jiebie = e[0].label;
			this.info.jiebie = e[0].value;
		},
		deptConfirm(e) {
			this.dept = e[0].label;
			this.info.deptId = e[0].value;
		},
		roleConfirm(e) {
			console.log(e);
			this.role = e[0].label;
			this.roleCode = e[0].value;
		},
		jcConfirm(e) {
			this.jieci = e[0].label + e[1].label;
			this.jieId = e[0].value;
			this.ciId = e[1].value;
		},
		navChange(index) {
			this.navIndex = index;
			this.loadData('refresh');
		},
		lirenConfirm(e) {
			this.liren = e[0].label;
			this.info.liren = e[0].value;
		},
		lianrenConfirm(e) {
			this.lianren = e[0].label;
			this.info.lianren = e[0].value;
		},
		confirm1(e) {
			console.log(e);
		},
		confirm2(e) {
			console.log(e);
		},
		confirm3(e) {
			console.log(e);
		},
		confirm4(e) {
			console.log(e);
		},
		filter() {
			this.show = false;
			this.loadData('refresh');
		},
		resert() {
			this.show = false;
			Object.keys(this.info).forEach((key) => {
				this.info[key] = '';
			});
			this.info.status = '1,2';
			this.info.clientCode = '370784';
			this.role = '';
			this.roleCode = 'changwei,weiyuan';
			this.sex = '';
			this.nation = '';
			this.birthday = '';
			this.xueli = '';
			this.dangpai = '';
			this.wyhdz = '';
			this.xsqhdz = '';
			this.jiebie = '';
			this.dept = '';
			this.depts = '人大代表';
			this.jieci = '';
			this.liren = '';
			this.lianren = '';
			this.loadData('refresh');
		},
		search(e) {
			this.info.name = e;
			this.loadData('refresh');
		},
		call(e) {
			uni.makePhoneCall({
				phoneNumber: e
			});
		},
		pageTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

<style lang="scss">
.list-view {
	background-color: #fff;
}

.list-box {
	padding: 0 30rpx;
}

.filter-box {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	touch-action: pan-y;
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}

.search-view {
	display: flex;

	.search-input {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.del {
		display: flex;
		align-items: center;
		margin-left: 20rpx;
		font-size: 14px;
		color: #666;
		line-height: 40rpx;
		word-break: keep-all;

		.image {
			margin-right: 14rpx;
			width: 22rpx;
			height: 28rpx;
		}
	}
}

.united-ttl {
	display: flex;
	align-items: center;
	padding: 20rpx 30rpx;
	font-size: 17px;
	color: #333;
	line-height: 48rpx;
	border-bottom: 2rpx solid $u-border-color;

	.right-icon {
		margin-left: 10rpx;
		transition: transform 0.4s;

		&.reverse {
			transform: rotate(-180deg);
		}
	}

	.image {
		margin-right: 20rpx;
		width: 44rpx;
		height: 40rpx;
	}

	.lv-flag {
		display: block;
		color: #e5231a;
	}

	.ttl-btn {
		margin: -6rpx 0 -6rpx auto;
		width: 140rpx;
		height: 60rpx;
		font-size: 14px;
		color: #666;
		line-height: 60rpx;
		text-align: center;
		border-radius: 4rpx;
		background-color: $u-bg-color;
	}
}

.check-box {
	flex: 1;
	min-width: 100%;

	.list-info_01,
	.list-info_02 {
		padding-left: 30rpx;
	}
}
</style>
